package com.corticon.dialogs.model;

import com.corticon.dialogs.util.GenericFunction;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import javax.persistence.Transient;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotEmpty;

/**
 *
 * @author Lifan Yang
 */
@MappedSuperclass
public class QuestionBase extends AuditableEntity {

    protected String refId;
    protected long version;
    protected String name;
    protected String text;
    protected String description;
    protected String helpText;
    protected static String listmodeText;
    protected static String listmodeDescription;
    protected String vocabularyname;
//    protected String vocabularyLabel;
//    protected String vocabularyFlagLabel;

    // ********** Retire Properties ********** //
    protected User retiredBy;
    protected Date retiredOn;
    protected String retiredNote;

    @Column(name = "ID", nullable = false)
    public String getRefId() {
        return refId;
    }

    public void setRefId(String refId) {
        this.refId = refId;
    }

    @Column(name = "VERSION", nullable = false)
    public long getVersion() {
        return version;
    }

    public void setVersion(long version) {
        this.version = version;
    }

    @Length(max = 255, message = "questionBase.name.length")
    @NotEmpty(message = "questionBase.validate.name.notEmpty")
    @Column(name = "NAME", length = 255)
    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Length(max = 1999, message = "questionBase.text.length")
    @Column(name = "TEXT", length = 1999)
    public String getText() {
        return this.text;
    }

    public void setText(String text) {
        this.text = text;
    }

    @Length(max = 255, message = "questionBase.description.length")
    @Column(name = "DESCRIPTION", length = 255)
    public String getDescription() {
        return this.description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Length(max = 255, message = "questionBase.helptext.length")
    @Column(name = "HELPTEXT", length = 255)
    public String getHelpText() {
        return this.helpText;
    }

    public void setHelpText(String helpText) {
        this.helpText = helpText;
    }

//    @NotEmpty(message = "questionBase.validate.vocabularyLabel.notEmpty")
//    @Column(name = "VOCABULARY_LABEL", nullable = false)
//    public String getVocabularyLabel() {
//        return this.vocabularyLabel;
//    }
//
//    public void setVocabularyLabel(String vocabularyLabel) {
//        this.vocabularyLabel = vocabularyLabel;
//    }
//
//    @NotEmpty(message = "questionBase.validate.vocabularyFlagLabel.notEmpty")
//    @Column(name = "VOCABULARY_FLAG_LABEL", nullable = false)
//    public String getVocabularyFlagLabel() {
//        return this.vocabularyFlagLabel;
//    }
//
//    public void setVocabularyFlagLabel(String vocabularyFlagLabel) {
//        this.vocabularyFlagLabel = vocabularyFlagLabel;
//    }
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "RETIRED_BY")
    public User getRetiredBy() {
        return retiredBy;
    }

    public void setRetiredBy(User retiredBy) {
        this.retiredBy = retiredBy;
    }

    @Length(max = 255, message = "questionBase.retirednote.length")
    @Column(name = "RETIRED_NOTE", length = 255)
    public String getRetiredNote() {
        return retiredNote;
    }

    public void setRetiredNote(String retiredNote) {
        this.retiredNote = retiredNote;
    }

    @Temporal(TemporalType.DATE)
    @Column(name = "RETIRED_ON")
    public Date getRetiredOn() {
        return retiredOn;
    }

    public void setRetiredOn(Date retiredOn) {
        this.retiredOn = retiredOn;
    }
    GenericFunction genFunction = new GenericFunction();

    @Transient
    public String getListmodeDescription() {
        if (description != null) {
            return genFunction.interceptStr(description, 70);
        } else {
            return description;
        }

    }

    @Transient
    public String getListmodeText() {
        if (text != null) {
            return genFunction.interceptStr(text, 66);
        } else {
            return text;
        }
    }

    public void setListmodeDescription(String listmodeDescription) {
        this.listmodeDescription = listmodeDescription;
    }

    public void setListmodeText(String listmodeText) {
        this.listmodeText = listmodeText;
    }
    @Length(max = 255, message = "questionBase.vacabularyname.length")
    @NotEmpty(message = "questionBase.validate.vacabularyname.notEmpty")
    @Column(name = "VOCABULARYNAME", length = 255)
	public String getVocabularyname() {
		return vocabularyname;
	}

	public void setVocabularyname(String vocabularyname) {		
		this.vocabularyname = vocabularyname;
	}
}
